/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.graficaluna.service.otros;

import com.graficaluna.dao.otros.PersonaDAO;
import dto.PersonaDTO;
import java.util.List;

/**
 *
 * @author rsaldana
 */
public class ServicioPersona {
    
    
    
    public void grabarPersona(PersonaDTO p){
        try {
            PersonaDAO dao = new PersonaDAO(); 
            if(dao.obtenerPersonaPorId(p.getCodigo())==null){              
                dao.insertarPersona(p);
            }else dao.actualizarPersona(p);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<PersonaDTO> listarPersonas(){
        try {
            PersonaDAO dao = new PersonaDAO();
            List<PersonaDTO> personas =dao.listarPersonas();            
            return personas;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public void eliminarPersona(Integer codigo){
        try {
            PersonaDAO dao = new PersonaDAO();
            dao.eliminarPersona(codigo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public List<PersonaDTO> buscarPersonasPorFiltro(String texto){
        try {
            PersonaDAO dao = new PersonaDAO();
            List<PersonaDTO> personas =dao.buscarPersonasPorFiltro(texto);
            return personas;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
   
    
}
